/*
 * anima/cmdline.hh - Command line parser interface.
 * Copyright (C) 2007  Mikhail Vorozhtsov
 * See the LICENSE section of the README file for details.
 */

/* $Id$ */

#ifndef HEADER_ANIMA_CMDLINE_HH
#define HEADER_ANIMA_CMDLINE_HH

START_NAMESPACE (anima)

class cmdline
{
public:
  struct option_t
  {
  public:
    enum type_t
    {
      TYPE_STRING,
      TYPE_INTEGER,
      TYPE_ENUM
    };

  public:
    const char *name;
    type_t type;
    union
      {
        u64_t length;
        struct
          {
            u64_t low;
            u64_t high;
            bool signed_p;
          };
        const char * const *items;
      } restrictions;

  private:
    bool *defined_p;
    union
      {
        struct
        {
          char *string;
          u64_t length;
        };
        u64_t *integer;
        const char **item;
      } value;

  public:
    INLINE
    option_t (const char *name, bool *defined_p, char *string, u64_t length)
      : name (name), defined_p (defined_p)
    {
      type = TYPE_STRING;
      restrictions.length = length;
      value.string = string;
    }

    INLINE
    option_t (const char *name, bool *defined_p, u64_t low, u64_t high,
              bool signed_p, u64_t *value)
      : name (name), defined_p (defined_p)
    {
      type = TYPE_INTEGER;
      restrictions.low = low;
      restrictions.high = high;
      restrictions.signed_p = signed_p;
      this->value.integer = value;
    }

    INLINE
    option_t (const char *name, bool *defined_p, const char * const items[],
              const char **item)
      : name (name), defined_p (defined_p)
    {
      type = TYPE_ENUM;
      restrictions.items = items;
      value.item = item;
    }

  public:
    bool set (const char *str, u64_t n) const;
    bool set (u64_t x) const;
  };

private:
  static const option_t *arch_options[];
  static const option_t *platform_options[];
  static const option_t *machine_options[];

public:
  static bool parse (const char *str, bool dry_run);
};

END_NAMESPACE

#endif /* HEADER_ANIMA_CMDLINE_HH */

